package com.jucai.pppeiyouclient.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {
    /**
     * 检查str是否为空或者空白，如果不为空返回str.trim(),否则返回""
     *
     * @param str
     * @return
     */
    public static String checkNull(String str) {
        if (str == null || str.length() == 0 || "".equals(str.trim())) {
            return "";
        }
        return str.trim();
    }

    public static boolean isEmpty(String str) {
        if (str == null || str.length() == 0 || "".equals(str.trim())) {
            return true;
        }

        return false;
    }

    public static boolean isNumber(String str) {
        java.util.regex.Pattern pattern = java.util.regex.Pattern
                .compile("[0-9]*");
        java.util.regex.Matcher match = pattern.matcher(str);
        if (match.matches() == false) {
            return false;
        } else {
            return true;
        }
    }

    public static boolean isChinese(String str) {
        java.util.regex.Pattern pattern = java.util.regex.Pattern
                .compile("[\\u4e00-\\u9fa5]+");
        java.util.regex.Matcher match = pattern.matcher(str);
        if (match.matches()) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean matchTel(String tel) {
        Pattern p = Pattern
                .compile("^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$");
        Matcher m = p.matcher(tel);
        return m.matches();
    }
}
